London | 26-ITP-May | Hugh Mills | Sprint 3 | 2. practice tdd - #1607
London | 26-ITP-May | Hugh Mills | Sprint 3 | 2. practice tdd#1607HM-127BTY wants to merge 6 commits into
Conversation
put in code using "if" function.
Making of code and tests
There was a problem hiding this comment.
semicolon missing in line 8 and line 11.
fun fact: In the original design of JavaScript, there was no semicolon, but it has been added later on - so that nowadays JS programmers generally follow the practice of adding semicolon.
| test("should count multiple occurrences of a character", () => { | ||
| const str = "aaa aa"; | ||
| const char = "a"; | ||
| const count = countChar(str, char); | ||
| expect(count).toEqual(5); | ||
| }); | ||
|
|
||
| test("should count multiple occurrences of a character with random characters", () => { | ||
| const str = "ajhyabhaakaka"; | ||
| const char = "a"; | ||
| const count = countChar(str, char); | ||
| expect(count).toEqual(6); | ||
| }) | ||
|
|
There was a problem hiding this comment.
The two cases looks quite similar, they both have random characters in the middle of str, and they both start with char, and they both end with char.
There was a problem hiding this comment.
not to sure what is ment here, I did do some adjustments
| // Scenario: No Occurrences | ||
| // Given the input string `str`, | ||
| // And a character `char` that does not exist within `str`. | ||
| // When the function is called with these inputs, | ||
| // Then it should return 0, indicating that no occurrences of `char` were found. | ||
| test("should return 0 with no occurrence of the character", () => { | ||
| const str ="abcd"; | ||
| const char = "e"; | ||
| const count = countChar(str, char); | ||
| expect(count).toEqual(0); | ||
| }); |
There was a problem hiding this comment.
There should be one more boundary case making char has no occurrence in str. Can you think of that special case?
There was a problem hiding this comment.
wracked my brain for this one and hit a blank, and advice would be great
There was a problem hiding this comment.
I think the question requires to also handle 2nd and 3rd etc. Since the question itself may not be quite clear about that, you may clarify in slack channel. Thanks.
There was a problem hiding this comment.
Will ask on there and if needed update the code with it. ^_^
There was a problem hiding this comment.
if the question requires to also handle 2nd and 3rd etc, then there will be more test cases.
|
I see in my haste I missed the two files, I have now done those and other fixes aswell, just waiting to see the response on Slack for that one test on the 2nd and 3rds needed or not. |
|
If there is no reply in Slack, I would still encourage you to code the 2nds and 3rds because:
Thank you for your great effort, and please keep it up :-) |
|
I have done that, I now have the code done for the 1 2 and 3, I have also added in tests for negative numbers and hopefully have it done for all numbers. ^_^ |
Learners, PR Template
Self checklist
Changelist
Added testing and code, starting with writing a test before adding code.